<template>
  <div>
    <video ref="videoPlayer" controls></video>
  </div>
</template>

<script>
export default {
  name: 'Base64VideoPlayer',
  props: {
    base64Video: {
      type: String,
      required: true
    }
  },
  mounted() {
    this.playBase64Video(this.base64Video);
  },
  methods: {
    playBase64Video(base64Video) {
		console.log(base64Video)
		console.log()
      // 解码 Base64 编码的字符串
      const videoBinaryString = atob(base64Video);

      // 将二进制字符串转换为字节数组
      const len = videoBinaryString.length;
      const bytes = new Uint8Array(len);
      for (let i = 0; i < len; i++) {
        bytes[i] = videoBinaryString.charCodeAt(i);
      }

      // 创建 Blob 对象
      const blob = new Blob([bytes], { type: 'video/mp4' });

      // 创建 URL 对象
      const url = URL.createObjectURL(blob);

      // 将 URL 设置为视频播放器的源
      this.$refs.videoPlayer.src = url;
    }
  }
};
</script>

<style scoped>
/* 添加你的样式 */
</style>
